import logging
from logging.handlers import TimedRotatingFileHandler
from os.path import dirname, sep

may_path = dirname(__file__) + sep


def init_log(log_path, debug=False):
    log_fmt = "%(asctime)s - %(levelname)s - %(module)s - %(funcName)s - %(message)s"
    if debug:
        handler = logging.StreamHandler()
        level = "DEBUG"
    else:
        handler = TimedRotatingFileHandler(log_path, "h", 1, 90, "utf-8")
        level = "INFO"
    logging.basicConfig(
        level=level,
        format=log_fmt,
        handlers=[handler]
    )


class ConfigError(Exception):
    pass


class Server:
    """this is a data structure class"""

    def __init__(self, host, user=None, port=None, **kwargs):
        self.user = user
        self.host = host
        self.port = port
        self.tag = []

    def is_in(self, tag):
        return tag in self.tag

    def add_parent_tag(self, tag):
        self.tag.insert(tag, 0)
